package com.hazardSoft.eStore.entities;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import com.hazardSoft.eStore.utils.QueryConstants;

@Entity
@NamedQueries({
	@NamedQuery(name = QueryConstants.QUERY_LIST_PRODUCTS, query = "FROM Product p ORDER BY p.name ASC"),
	@NamedQuery(name = QueryConstants.QUERY_SEARCH_PRODUCT_BY_NAME, query = "FROM Product pr WHERE pr.name=?1")
})
public class Product implements Serializable {
	@Id
	private Integer id;

	@Lob
	private String name;

	@Lob
	private String description;

	@ManyToOne
	@JoinColumn(name="brand")
	private Brand brand;

	private Double cost;

	@ManyToOne
	@JoinColumn(name="category")
	private Category category;

	@ManyToOne
	@JoinColumn(name="offer")
	private Offer offer;
	
	@Lob
	private byte[] image;

//	@OneToMany(mappedBy="product")
//	private Set<Inventory> inventoryCollection;

//	@OneToMany(mappedBy="product")
//	private Set<Sale> saleCollection;

	private static final long serialVersionUID = 1L;

	public Product() {
		super();
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Brand getBrand() {
		return this.brand;
	}

	public void setBrand(Brand brand) {
		this.brand = brand;
	}

	public Double getCost() {
		return this.cost;
	}

	public void setCost(Double cost) {
		this.cost = cost;
	}

	public Category getCategory() {
		return this.category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public Offer getOffer() {
		return this.offer;
	}

	public void setOffer(Offer offer) {
		this.offer = offer;
	}

	public byte[] getImage() {
		return image;
	}

	public void setImage(byte[] image) {
		this.image = image;
	}

//	public Set<Inventory> getInventoryCollection() {
//		return this.inventoryCollection;
//	}
//
//	public void setInventoryCollection(Set<Inventory> inventoryCollection) {
//		this.inventoryCollection = inventoryCollection;
//	}
//
//	public Set<Sale> getSaleCollection() {
//		return this.saleCollection;
//	}
//
//	public void setSaleCollection(Set<Sale> saleCollection) {
//		this.saleCollection = saleCollection;
//	}
	public boolean equals(Object object){
		if (object == null) {
			return false;
		}
		if (!(object instanceof Product)) {
			return false;
		}
		Product product = (Product) object;
		if (product == null) {
			return false;
		}
		if (!product.getId().equals(this.getId())) {
			return false;
		}
		return true;
	}
}
